package org.chench.extra;

import org.zeromq.SocketType;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

/**
 * 统计任务结果
 * @author chench9@lenovo.com
 * @desc org.chench.extra.TaskSink
 * @date 3/20/19 7:21 PM
 */
public class TaskSink {
    public static void main(String[] args) {
        startSink();
    }

    private static void startSink() {
        try (ZContext context = new ZContext()){
            ZMQ.Socket receiver = context.createSocket(SocketType.PULL);
            receiver.bind("tcp://*:5558");

            // 循环处理100次
            long tstart = System.currentTimeMillis();
            int task_nbr;
            for (task_nbr = 0; task_nbr < 100; task_nbr++) {
                String string = new String(receiver.recv(0), ZMQ.CHARSET).trim();
                if ((task_nbr / 10) * 10 == task_nbr) {
                    System.out.print(":");
                }
                else {
                    System.out.print(".");
                }
            }

            //  Calculate and report duration of batch
            long tend = System.currentTimeMillis();

            System.out.println("\nTotal elapsed time: " + (tend - tstart) + " msec");

        }


    }
}
